

<?php
$servername = "mysql";
$username = "root";
$password = "password";
$dbname = "test";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
if (isset($_GET["delete"])) {
    $id = $_GET["id"];
    $sql = "delete from task where id = $id";
} else {
    if (isset($_POST["name"])) {
        $sql = "insert into task(name,description) values('".$_POST["name"]."','".$_POST["description"]."')";
    } else if (isset($_POST["id"])) {
        $id = $_POST["id"];
        $name = $_POST["name"];
        $description = $_POST["description"];
        $sql = "update task set name = '$name', description= '$description' where id = '$id'";
    }
}

if ($conn->query($sql) === TRUE) {
    echo "成功";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}


$conn->close();
?>
<ul>
    <li><a href="/task/task_form.php">新增</a></li>
    <li><a href="/task/list.php">列表</a></li>
</ul>




